package org.batallademusica.dao;

import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class EntityManagerFactorySingleton {
	private EntityManagerFactory emf;
	private static final EntityManagerFactorySingleton  singleton=new EntityManagerFactorySingleton();
	
	public static EntityManagerFactorySingleton getInstance(){
		return singleton;
	}
	
	private EntityManagerFactorySingleton(){
	}
	
	public EntityManagerFactory getEntityManagerFactory(){
		if(this.emf==null)
			this.createEntityManagerFactory();
		return this.emf;
	}
	
	public void closeEntityManagerFactory(){
		if(this.emf!=null && this.emf.isOpen()){
			this.emf.close();
			this.emf=null;
		}
	}
	private void createEntityManagerFactory(){
		this.emf=Persistence.createEntityManagerFactory("batallaDeMusica");
	}
	
}
